package cn.lanqiao.ui;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;

import cn.lanqiao.service.impl.ProjectServiveImpl;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ApplyFrm extends JInternalFrame {
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ApplyFrm frame = new ApplyFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ApplyFrm() {
		setClosable(true);
		setBorder(null);
		getContentPane().setFont(new Font("Microsoft New Tai Lue", Font.PLAIN, 20));
		getContentPane().setBackground(Color.WHITE);
		setTitle("立即报名");
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("请选择报名项目");
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		lblNewLabel.setBounds(10, 10, 90, 41);
		getContentPane().add(lblNewLabel);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 50, 430, 160);
		getContentPane().add(scrollPane);
		
		cn.lanqiao.service.ProjectService ps=new cn.lanqiao.service.impl.ProjectServiveImpl();
		Object[][]object=ps.getAllProjects();
		table = new JTable();
		Object[] header= {"p_id","项目名称","价格"};
		table.setModel(new DefaultTableModel(
			object,header
		));
		scrollPane.setViewportView(table);
		
		JButton btnNewButton = new JButton("确认报名");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int rowIndex=table.getSelectedRow();
				String s="您已选择"+table.getValueAt(rowIndex, 1).toString()+"项目";
				System.out.println(rowIndex+" "+s);
				
				int val=JOptionPane.showConfirmDialog(null,"确认报名吗？",s,JOptionPane.YES_NO_CANCEL_OPTION);
				System.out.println(val);
			}
		});
		btnNewButton.setToolTipText("");
		btnNewButton.setBounds(304, 240, 93, 23);
		getContentPane().add(btnNewButton);
		
	}
}
